package cn.edu.jxust.core.infrastructure.util.authc;

import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
import java.util.Objects;

@Data
@Component
@PropertySource("classpath:config/jwt-config.properties")
public class JwtProperties {

    private final Environment env;

    /**
     * token过期时间，单位分钟
     */
    private Integer tokenExpireTime;

    /**
     * token加密密钥
     */
    private String secretKey;

    /**
     * 构造方法
     * @param env 上下文环境
     */
    @Autowired
    public JwtProperties(Environment env) {
        this.env = env;
        this.tokenExpireTime = Integer.parseInt(Objects.requireNonNull(env.getProperty("tokenExpireTime")));
        this.secretKey = env.getProperty("secretKey");
    }

}
